/*
 * Copyright (C) 2018 guomw.Inc. All rights reserved.
 * 项目名称： report-manage
 * 文件名称： SystemMenuRepository.java
 * Date：18-11-5 上午10:54
 * Author: guomw
 */

package com.guomw.report.service.repository.system;

import com.guomw.report.service.entity.SystemMenu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 系统菜单Repository
 * @author guomw
 * @date 2018/9/17
 */
@Repository
public interface SystemMenuRepository extends JpaRepository<SystemMenu,Integer>,JpaSpecificationExecutor<SystemMenu> {

    /**
     * 更新启用状态
     * @param itemCode
     * @param enable
     * @return
     */
    @Query("update SystemMenu m set m.itemEnable=?2 where m.itemCode=?1")
    @Modifying(clearAutomatically = true)
    @Transactional(rollbackFor = RuntimeException.class)
    int updateEnableByItemCode(Integer itemCode,boolean enable);

    /**
     * 根据菜单ID，获取菜单数据
     * @param menuIds
     * @param itemFunction 是否是功能菜单
     * @return
     */
    @Query("select u from SystemMenu u where u.itemCode in ?1 and u.itemFunction=?2")
    List<SystemMenu> findInMenuIds(List<Integer> menuIds,boolean itemFunction);
}
